package com.scuec.tourismwebsite.controller;

import com.scuec.tourismwebsite.entity.FreeformPostLike;
import com.scuec.tourismwebsite.entity.PostLike;
import com.scuec.tourismwebsite.service.PostLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("tour/v1")
public class PostLikeController {
    @Autowired
    private PostLikeService postLikeService;

    @GetMapping("like")
    public List<PostLike> selectPostLikeById(@RequestParam("user_id") int user_id, @RequestParam("post_id") int post_id){
        return postLikeService.selectPostLikeById(user_id,post_id);
    }

    @PostMapping("like/{user_id}/{post_id}")
    public int insertPostLike(@PathVariable("user_id") int user_id, @PathVariable("post_id") int post_id){
        return postLikeService.insertPostLike(user_id, post_id);
    }

    @DeleteMapping("like")
    public int deletePostLike(@RequestParam("user_id") int user_id, @RequestParam("post_id") int post_id){
        return postLikeService.deletePostLike(user_id, post_id);
    }

    @GetMapping("likes/{user_id}")
    public List<PostLike> selectLikesByUserId(@PathVariable("user_id") int user_id) {
        List<PostLike> likes = postLikeService.selectLikesByUserId(user_id);
        return likes;
    }

}
